package com.xhai.common.domain.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author xhai
 * @description 实体基类
 * @date 2025/5/24
 */
@Data
@Schema(name = "BaseEntity", description = "实体基类")
public class BaseEntity implements Serializable {
    @Serial
    private static final long serialVersionUID = 7289969248134709992L;

    /**
     * 状态（0停用，1正常）
     */
    @TableField(value = "status")
    @Schema(description = "状态（0停用，1正常）")
    private Character status;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    /**
     * 创建人
     */
    @TableField(value = "create_username", fill = FieldFill.INSERT)
    @Schema(description = "创建人")
    private String createUsername;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    /**
     * 更新人
     */
    @TableField(value = "update_username", fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新人")
    private String updateUsername;

    /**
     * 逻辑删除标志（0未删除，1已删除）
     */
    @TableField(value = "logic_del_flag", fill = FieldFill.INSERT)
    @Schema(description = "逻辑删除标志（0未删除，1已删除）")
    @TableLogic(value = "0", delval = "1")
    private Character logicDelFlag;

    /**
     * 乐观锁字段（版本号）
     */
    @Version
    @Schema(description = "乐观锁字段（版本号）")
    @TableField(value = "version", fill = FieldFill.INSERT)
    private Integer version;
}
